<?php
declare (strict_types = 1);

namespace app\admin\controller;
use think\facade\View;
use think\facade\Db;
class Deposit extends \app\admin\controller\Base
{
  
  public function _filter()
  {
    $query = [];
    $source = input('source');
    if ($source) {
      $query[] = ['source','=',$source];
    }

    $status = input('status');
    if ($status) {
      $query[] = ['status','=',$status];
    }

    return $query;
  }

  public function pass()
  {
    $id = input('id');
    
    Db::name('deposit')->where('id',$id)->update([
      'status'=>1,
    ]);
    return $this->doSuccess('ok');
    # code...
  }

  public function reAuth()
  {
    $id = input('id');
    $remark = input('remark');
    $status = input('status');
    if ($status == -1 && $remark == '') {
      return $this->doError('请输入备注');
    }
    
    Db::name('deposit')->where('id',$id)->update([
      'status'=>$status,
      'remark'=>$remark,
    ]);
    return $this->doSuccess('ok');
    # code...
  }

  public function updateAuth()
  {
    $id = input('id');
    $remark = input('remark');
    if (!$remark) {
      return $this->doError('请输入退回备注');
    }
    Db::name('deposit')->where('id',$id)->update([
      'remark'=>$remark,
      'status'=>-1,
    ]);
    return $this->doSuccess('ok');
  }

  public function ckvo($vo ='')
  {
    $user = Db::name('user')->field('id,nick,head')->where('id',$vo['uid'])->find();
    if (!$user) {
      $user['head'] = '';
      $user['nick'] = '';
      $user['pid'] = 0;
    }
    $vo['user'] = $user;

    if ($vo['status'] == 0) {
      $vo['status_txt'] = '待审核';
    }
    return $vo;
  }
}
